package com.java.struts.menu.action;

import com.java.struts.base.action.BaseAction;
import com.java.struts.menu.entity.MenuinfoEntity;
import com.java.struts.menu.service.MenuinfoService;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import java.util.List;
import java.util.Map;

public class MenuinfoAction extends BaseAction {
    private MenuinfoService menuinfoService=new MenuinfoService();
    private Integer meid;
    public Integer getMeid() {
        return meid;
    }
    public void setMeid(Integer meid) {
        this.meid = meid;
    }

    private String mname;

    public String getMname() {
        return mname;
    }

    public void setMname(String mname) {
        this.mname = mname;
    }

    private MenuinfoEntity menuinfoEntity=new MenuinfoEntity();
    public MenuinfoEntity getMenuinfoEntity() {
        return menuinfoEntity;
    }
    public void setMenuinfoEntity(MenuinfoEntity menuinfoEntity) {
        this.menuinfoEntity = menuinfoEntity;
    }

    /**
     * 查询所有菜品信息
     * @return
     */
    @Action(value="listMenu")
    public String queryMenu(){
        List<MenuinfoEntity>  listMenu = menuinfoService.listMenu();
            setSuccessResult(listMenu);
        return "json";
        }

    /**
     * 查询单个菜品
     * @return
     */
    @Action(value="queryMMname",results={
            @Result(name="json",location="/editMenu.jsp")})
    public String queryMenuMname(){
        MenuinfoEntity menuinfoEntity = menuinfoService.queryMenuMname(meid);
        ActionContext context = ActionContext.getContext();
        Map<String, Object> session = context.getSession();
        session.put("menu",menuinfoEntity);
        return "json";
    }
    /**
     * 通过菜品id删除菜品信息
     */
    @Action(value="deleteMenu")
    public String deleteMenu(){
        menuinfoService.deleteMenu(meid);
        return "json";
    }
    /**
     * 添加菜品信息
     * @return
     */
    @Action(value="addMenu",results = {
            @Result(name="addMenu",location = "/menu.jsp")
    })
    public String addMenu(){
        menuinfoService.addMenu(menuinfoEntity);
        return "addMenu";
    }
    }
